<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>软件资源</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: #181818;
            font-weight: 300;
            color: white;
        }

        .container {
            display: grid;
            justify-content: space-between;
            grid-template-columns: repeat(auto-fill, 300px);
            padding: 60px 140px 0px 140px;
        }

        .box {
            /* margin: 1%; */
            width: 250px;
            height: 150px;
            background: rgb(40, 40, 40);
            margin-top: 30px;
            padding: 10px;
            margin: 10px;
        }

        .header {
            position: fixed;
            width: 100%;
            background: rgb(30, 30, 30);
            height: 50px;
            line-height: 50px;
            font-size: 8px;
            padding-left: 30px;
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            padding-right: 2rem;
        }
    </style>

    <style>
        .box_header {
            width: auto;
            font-size: 8px;
            font-size: 10px;
            transform: scale(0.8);
            transform-origin: 0% 0%;
            padding: 3px;
            margin: 2px;
        }

        .box_header_box {
            background: #31456a;
            color: #00cad6;
            border-radius: 5px;
            padding: 4px;
        }
        img {
            width: 60px;
            height: 60px;
            display: block;
            margin: 0 auto;
            overflow: hidden;
            border-radius: 5px;
        }

        img:hover,
        .box_header_box:hover {
            opacity: 0.7;
        }

        .block_text {
            text-align: center;
            margin: 10px;
            margin-top: 20px;

        }

        .fa-home {
            font-size: 13px;
            color: #00cad6;
        }

        .author {
            transform: scale(0.8);
            font-size: 0.8rem;
            color: rgb(156, 193, 235);
            cursor: pointer;
        }

        #template {
            display: inline;
        }

        .header_nav_item {
            font-size: 0.4rem;
            padding: 1rem;
            cursor: pointer;
        }

        .header_nav_item_active {
            font-size: 0.4rem;
            padding: 1rem;
            cursor: pointer;
            background: #00cad6;
            line-height: 100%;
        }
        .box {}
        @media screen and (max-width:1000px) {
            .box_header_box{
                font-size: 15px;
            }
            img {
                width: 100px;
                height: 100px;
                display: block;
                margin: 0 auto;
                overflow: hidden;
                border-radius: 5px;
            }
            .box {
                /* margin: 1%; */
                width: 280px;
                height: 200px;
                background: rgb(40, 40, 40);
                margin-top: 30px;
                padding: 10px;
                margin: 10px;
            }
            .header_nav_item:nth-child(n+3) {
                /* margin: 1%; */
                display: none;
            }
            .container {
                display: flex;
                flex-wrap: wrap;
                justify-content: center;
                padding: 60px 20px 0px 20px;
            }
        }
    </style>


</head>

<body>
    <div class="header">
        <h1>收藏博客</h1>
        <div class="header_nav">
            <span class="header_nav_item header_nav_item_active">团队博客</span>
            <span class="header_nav_item ">个人博客</span>
            <span class="header_nav_item">前端周刊</span>
            <span class="header_nav_item">js技巧</span>
            <span class="header_nav_item">图标</span>
            <span class="header_nav_item">文档</span>
            <span class="header_nav_item ">工具学习</span>
        </div>
    </div>

    <div class="container">
        <template id="template-task">
            <div class="box">
                <div class="box_header">
                    <span class="box_header_box">Band 6</span>
                </div>
                <img src="./resource/everest.jpg" alt="">
                <div class="block_text" src="./resource/applewatch.hwt">
                    <i class="fa fa-home"></i>
                    <span class="author">作者</span>
                </div>
            </div>
        </template>
    </div>
    
    <script>
        
    </script>
    <script>
        // 加载数据的方法
        function loadData(data) {
            
            const taskTemplate = document.querySelector('#template-task');
            let domArray = []
            for (let i of data) {
                let taskDOM = taskTemplate.content.firstElementChild.cloneNode(true);
                taskDOM.querySelector(".box_header_box").innerHTML = i.band
                taskDOM.querySelector("img").setAttribute("src", `./resource/${i.img}.png`)
                taskDOM.querySelector(".block_text").setAttribute("src", `${i.src}`)
                taskDOM.querySelector(".author").innerHTML = i.author;
                document.querySelector(".container").append(taskDOM)
            }
            document.querySelectorAll(".block_text").forEach((v) => {
                v.addEventListener("click", (e) => {
                    let src = v.getAttribute("src")
                    window.open(src)
                }, false)
            })
        }
    </script>


    <script type="module">
        import {teamData,personData,jsData,weekData,toolData,imgData} from './data.js'
        // 初始化数据
        loadData(teamData)
        //头顶的切换逻辑
        document.querySelector(".header_nav").addEventListener("click", (e) => {
            document.querySelectorAll(".header_nav_item").forEach((v) => {
                v.classList.remove("header_nav_item_active")
            })
            
            window.location = String(window.location).split("#")[0] + '#' + e.target.innerHTML
            document.querySelectorAll(".box").forEach((e)=>{
                e.remove()
            })
            if(e.target.innerHTML == "团队博客"){
                loadData(teamData)
            }
            if(e.target.innerHTML == "个人博客"){
                loadData(personData)
            }
            if(e.target.innerHTML == "前端周刊"){
                loadData(weekData)
            }
            if(e.target.innerHTML == "js技巧"){
                loadData(jsData)
            }
            if(e.target.innerHTML == "图标"){
                loadData(imgData)
            }
            if(e.target.innerHTML == "工具学习"){
                loadData(toolData)
            }
            if(!Array.from(e.target.classList).includes("header_nav")){
                e.target.classList.add("header_nav_item_active")
            }
           
        })

    </script>
</body>

</html>